{layout name="layout"}
<div class="panel">
    <div class="panel-body">
        <div class="pad-btm form-inline">
            <div class="row">
                <div class="col-sm-6 table-toolbar-left">
                    <button class="btn btn-default" data-target="#apis-modal" data-toggle="modal"><i class="fa fa-plus-circle"></i> 添加接口</button>
                </div>
            </div>
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead class="bg-gray-dark">
                        <tr>
                            <th class="text-center ">接口名称</th>
                            <th class="text-center ">版本</th>
                            <th class="text-center ">URI</th>
                            <th class="text-center ">接口描述</th>
                            <th class="text-center ">更新时间</th>
                            <th class="text-center ">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    {if $apis}
                    {foreach $apis as $api}
                        <tr>
                            <td class="text-center ">{$api.apiname}</td>
                            <td>{$api.version}</td>
                            <td>{$api.URI}</td>
                            <td>{$api.description}</td>
                            <td class="text-center ">{$api.mtime}</td>
                            <td class="text-center ">
                                <div class="btn-group">
                                    <button class="btn btn-default" data-target="#apis-modal" data-toggle="modal" data-apiid="{$api.id}"><i class="fa fa-pencil-square-o"></i></button>
                                    <button class="btn btn-default" onclick='del_api(this,"{$api.id}")'><i class="ion-trash-b"></i></button>
                                </div>
                            </td>
                        </tr>
                    {/foreach}
                    {/if}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{include file="modals/apis-modal"}
<script type="text/javascript">
    function del_api(e,apiid){
        bootbox.setDefaults({locale:"zh_CN"});
        bootbox.confirm("确定删除吗", function(result) {
            if(result){
                $.ajax({
                    url:"{:url('api/apis/del_api')}",
                    type:"post",
                    data:{"apiid":apiid},
                    dataType:"json",
                    success:function(result){
                        if(result.status == 'success'){
                            $.niftyNoty({
                                type: 'success',
                                icon : 'pli-exclamation icon-2x',
                                message : result.msg,
                                container : 'floating',
                                timer : 1500,
                            });
                            $(e).parents('tr').detach();
                        }else{
                            $.niftyNoty({
                                type: 'warning',
                                icon : 'pli-exclamation icon-2x',
                                message : result.msg,
                                container : 'floating',
                                timer : 1500,
                            });
                        }
                    },
                    error:function(){
                        $.niftyNoty({
                            type: 'danger',
                            icon : 'pli-exclamation icon-2x',
                            message : '网络连接失败',
                            container : 'floating',
                            timer : 1500,
                        });
                    }
                });
            }
        })
    }
</script>